﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace class9Homework
{
    public partial class Form1 : Form
    {
        string url;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                url = textBox1.Text;
                string mailMatch = @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}";
                string teleMatch = @"(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}";
                string urlMatch = @"\b(\S+)://(\S+)\b";
                bool isURLMatch;
                isURLMatch = Regex.IsMatch(url, urlMatch);
                if (!isURLMatch)
                {
                    label4.Text = "输入的url不合法，请重新输入";
                    label3.Text = "";
                }
                else
                {
                    label4.Text = "";
                    WebClient client = new WebClient();
                    client.Encoding = Encoding.UTF8;
                    String pageHtml = client.DownloadString(url);
                    Regex mailrx = new Regex(mailMatch);
                    Regex telerx = new Regex(teleMatch);
                    MatchCollection mails = mailrx.Matches(pageHtml);
                    MatchCollection teles = telerx.Matches(pageHtml);
                    String textShow = "";
                    textShow = textShow + "邮箱:" + "\n";
                    foreach (Match mail in mails)
                    {
                        textShow = textShow + mail + "\n";
                    }
                    textShow = textShow + "电话:" + "\n";
                    foreach (Match tele in teles)
                    {
                        textShow = textShow + tele + "\n";
                    }
                    label3.Text = textShow;

                }
            }
            catch (Exception)
            {

            }

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
